package com.example.apigateway.handle;

import com.example.apigateway.Utils.ResultVOUtil;
import com.example.apigateway.VO.ResultVO;
import com.example.apigateway.exception.CreditException;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultVO handle(Exception e) {
        if(e instanceof CreditException) {
            CreditException creditException = (CreditException) e;
            return ResultVOUtil.error(creditException.getCode(),creditException.getMessage());
        }else {
            return ResultVOUtil.error(-1,"系统未知错误");
        }
    }
}
